﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web.Routing;
using System.Reflection;

namespace K3R.Web.Routing.Test {
	class Program {
		static void Main(string[] args) {
			var routing = ConfigurationManager.GetSection("k3r.web.routing") as RouteConfig;
			Console.WriteLine(routing.Routes.Count);

			//var type = routing.Routes[0].Handler.Split(',')[0];
			//var assembly = routing.Routes[0].Handler.Split(',')[1];
			//IVirtualRouteHandler handler = Activator.CreateInstance(assembly, type).Unwrap() as IVirtualRouteHandler;
			//handler.SetVirtualPath(routing.Routes[0].VirtualPath);
			//Console.WriteLine(handler.GetType());

			Console.WriteLine("Fields of MyClass");
			Type t = typeof(Class1);

			//m.GetCustomAttributes()
			Console.WriteLine("Methods of MyClass");
			foreach (MethodInfo m in t.GetMethods()) {
				Console.WriteLine("{0}", m);
				foreach (ParameterInfo p in m.GetParameters()) {
					Console.WriteLine("  Param: {0} {1}",
					p.ParameterType, p.Name);
				}
				PrintAttributes(typeof(System.Reflection.MethodAttributes), (int)m.Attributes);
			}
			
			Console.ReadLine();
		}

		public static void PrintAttributes(Type attribType, int iAttribValue) {
			if (!attribType.IsEnum) {
				Console.WriteLine("    This type is not an enum.");
				return;
			}

			FieldInfo[] fields = attribType.GetFields(BindingFlags.Public | BindingFlags.Static);
			for (int i = 0; i < fields.Length; i++) {
				int fieldvalue = (Int32)fields[i].GetValue(null);
				if ((fieldvalue & iAttribValue) == fieldvalue) {
					Console.WriteLine("    " + fields[i].Name);
				}
			}
		}
	}
}
